/*
 * Rectangle and color classes. Don't know if Avid derives them from AObject, 
 * but for our purposes, there is currently no need to.
 *
 * ABins uses these to store rectangle and color version as part of the bin 
 * structure.
 *
 * I only know what Avid calls these classes from error/debug messages, so they
 * are probably not really representative of Avid's own. Avid may even use 
 * classes of a different name for storing these values in bins.
 *
 * Most of these serialize themselves by writing a version byte and then their
 * data.
 *
 *  Created by Peter on 23.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef AV_TYPES_H
#define AV_TYPES_H

#include "TrCompat.h"
#include <iostream>

class AStream;

/*
 * Rectangle
 */
struct AvRect
{
	Int16 _values[ 4 ];

	void readFromStream( AStream& str );
	void writeToStream( AStream& str ) const;
	
	void dump( std::ostream& str ) const;
};

std::ostream& operator<<( std::ostream& str, const AvRect& rect );

struct AvRgbColor
{
	// Even though the DomainData subsys dumps list these as short, they may 
	// actually be unsigned since negative values tend to come up from time to
	// time.
	Int16 _values[ 3 ];
	
	void readFromStream( AStream& str );
	void writeToStream( AStream& str ) const;
	
	void dump( std::ostream& str ) const;
};

std::ostream& operator<<( std::ostream& str, const AvRgbColor& color );

// If need be, we can replace this with the awesome Rational class from Tropic's
// core layer.
struct Rational
{
	// Size/type of these fields not 100% certain
	Int32 numerator;
	Int32 denominator;
	
	void readFromStream( AStream& str );
	void writeToStream( AStream& str ) const;
	
	void dump( std::ostream& str ) const;	
};

std::ostream& operator<<( std::ostream& str, const Rational& r );

// GUID compatible. This is compatible with the class of the same name in the
// Avid AVX SKD. Avid seems to use this internally for storing UIDs.
struct acfUID
{
	UInt32 Data1;
	UInt16 Data2;
	UInt16 Data3;
	UInt8  Data4[ 8 ];
	
	// This reads the data from the stream exactly as it is. If the UID is 
	// stored as data in an AObjDoc, use readAcfUidFromObjDocStream() instead 
	// since that is able to deal with all the TagMarks that are interspersed 
	// correctly. In AMediaDesc, however, the UID is stored as pure binary.
	void readFromStream( AStream& str );
};

std::ostream& operator<<( std::ostream& str, const acfUID& uid );

void readAcfUidFromObjDocStream( AStream& str, acfUID& uid );

// This is the class from the AAF SDK, which Avid seems to use internally for 
// storing MOB IDs.
// This doesn't have serialization member functions since when it is written to
// files, there are lots of tag marks interspersed.
// Avid seems to use a typedef struct _aafMCMobID_t{...} aafMCMobID_t, but we're
// in the age of C++ now. Take that, Avid engineers! (In all fairness, though,
// they are doing an awesome job and for a codebase this old, the Avid seems to
// be surprisingly modern in many respects). But I digress.
struct aafMCMobID_t
{
	UInt8  SMPTELabel[ 12 ]; // 12-bytes of label prefix
	UInt8  length;
	UInt8  instanceHigh;
	UInt8  instanceMid;
	UInt8  instanceLow;
	acfUID material;
};

std::ostream& operator <<( std::ostream& str, const aafMCMobID_t& mobId );

// Use this to read a MobID from a bin or project file
// TODO: Migrate the reading code from AComposition::readFromStream() to here
void readMobIdFromAObjDocStream( AStream& str, aafMCMobID_t& mobId );

#endif /*Inclusion Gurad*/